package com.zbkj.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.activity.SfullDiscountActivity;
import com.zbkj.common.model.activity.SfullDiscountProduct;
import com.zbkj.common.model.product.Product;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.merchant.MerchantSfullDiscountSearchRequest;
import com.zbkj.service.dao.MerchantSfullDiscountActivityDao;
import com.zbkj.service.dao.MerchantSfullDiscountProductDao;
import com.zbkj.service.service.MerchantService;
import com.zbkj.service.service.MerchantSfullDiscountActivityService;
import com.zbkj.service.service.MerchantSfullDiscountProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * MerchantSfullDiscountActivityServiceImpl 接口实现
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Service
public class MerchantSfullDiscountActivityServiceImpl extends ServiceImpl<MerchantSfullDiscountActivityDao, SfullDiscountActivity> implements MerchantSfullDiscountActivityService {

    @Resource
    private MerchantSfullDiscountActivityDao dao;

    /**
     * 商户满减折扣列表
     * @param request 请求参数
     * @return List
     */
    @Override
    public PageInfo<SfullDiscountActivity> findPage(MerchantSfullDiscountSearchRequest request, PageParamRequest pageParamRequest) {
        LambdaQueryWrapper<SfullDiscountActivity> lqw = Wrappers.lambdaQuery();
        lqw.eq(Objects.nonNull(request.getMerId()), SfullDiscountActivity::getMerId, request.getMerId());
        lqw.eq(StringUtils.isNotBlank(request.getActiveType()), SfullDiscountActivity::getActiveType, request.getActiveType());
        lqw.eq(Objects.nonNull(request.getIsOpen()), SfullDiscountActivity::getIsOpen, request.getIsOpen());
        lqw.eq(Objects.nonNull(request.getStatus()), SfullDiscountActivity::getStatus, request.getStatus());
        lqw.eq(SfullDiscountActivity::getIsDel, false);
        List<SfullDiscountActivity> activityList = dao.selectList(lqw);
        Page<Product> page = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        return CommonPage.copyPageInfo(page, activityList);
    }

    @Override
    public List<SfullDiscountActivity> findAllist(MerchantSfullDiscountSearchRequest request) {
        LambdaQueryWrapper<SfullDiscountActivity> lqw = Wrappers.lambdaQuery();
        lqw.eq(Objects.nonNull(request.getMerId()), SfullDiscountActivity::getMerId, request.getMerId());
        lqw.in(Objects.nonNull(request.getIds())&&request.getIds().size()>0, SfullDiscountActivity::getId, request.getIds());
        lqw.eq(StringUtils.isNotBlank(request.getActiveType()), SfullDiscountActivity::getActiveType, request.getActiveType());
        lqw.eq(Objects.nonNull(request.getIsOpen()), SfullDiscountActivity::getIsOpen, request.getIsOpen());
        lqw.eq(Objects.nonNull(request.getStatus()), SfullDiscountActivity::getStatus, request.getStatus());
        lqw.eq(SfullDiscountActivity::getIsDel, false);
        return dao.selectList(lqw);
    }

    @Override
    public SfullDiscountActivity activityDetail(Integer id) {
        SfullDiscountActivity activity = dao.selectById(id);
        return activity;
    }

    /**
     * 新增商户满减折扣
     * @param activity 请求参数
     * @return 新增结果
     */
    @Override
    public Boolean add(SfullDiscountActivity activity) {
        return dao.insert(activity)>0 ? true:false;
    }

    /**
     * 修改商户满减折扣
     * @param activity 请求参数
     * @return 修改结果
     */
    @Override
    public Boolean updateSfullDiscount(SfullDiscountActivity activity) {
        return dao.updateById(activity)>0 ? true:false;
    }

    /**
     * 删除商户满减折扣
     * @param id 商户满减折扣ID
     * @return 删除结果
     */
    @Override
    public Boolean delete(Integer id) {
        return dao.deleteById(id)>0 ? true:false;
    }
}

